package com.it.od.od20221203;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author: liminghui
 * @date: 2022/12/3 15:15
 * @version: 1.0
 * @description: 字符串解密
 * 用例1
 * 123admyffc79pt
 * ssyy
 * 用例2
 * 123admyffc79ptaagghi2222smeersst88mnrt
 * ssyyfgh
 * 用例3
 * abcmnq
 * rt
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String str1 = sc.nextLine();
        String str2 = sc.nextLine();

        // 去扰子串
        String[] split = str1.split("[0-9a-f]+");
        List<String> list = Arrays.stream(split).filter(x -> !"".equals(x)).collect(Collectors.toList());

        // 记录最大字符串
        String maxStr = "";
        for (String str : list) {
            int len = computeLen(str);
            int len2 = computeLen(str2);
            int maxLen = computeLen(maxStr);
            if (len <= len2) {
                if (len > maxLen) {
                    maxStr = str;
                } else if (len == maxLen) {
                    maxStr = maxStr.compareTo(str) < 0 ? str : maxStr;
                }

            }
        }
        if ("".equals(maxStr)) {
            System.out.println("Not Found");
        } else {
            System.out.println(maxStr);
        }

    }

    public static int computeLen(String str) {
        char[] chars = str.toCharArray();
        Set<Character> set1 = new HashSet<>();
        for (char aChar : chars) {
            set1.add(aChar);
        }
        return set1.size();
    }

}
